import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/controllers/base/base_controller.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/date_tool.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'state.dart';

class DurationLogic extends BaseController {
  final DurationState state = DurationState();

  goBackSleepPage() {
    Get.back();
  }

  @override
  String getRemotePath() {
    throw '';
  }

  @override
  void initState() {
    state.duration = Get.arguments['value'] ?? 0;
    state.level = Get.arguments['level'] ?? '';
    state.color = Get.arguments['color'] ?? 0x00000000;
  }

  @override
  void onRemoteEvent(event, method) {
    // TODO: implement onRemoteEvent
  }

  String getPercentValueText() {
    return DateTool.second2HM(state.duration * 60);
  }

  /// 睡眠时长参考值计算:6-10小时为正常，小于6小时为偏低，大于10小时为偏高
  getLevelText() {
    int duration = state.duration ~/ 60;
    if (duration < 6) {
      return Text(LocaleKeys.sleep_ratio_low.ts, style: TextStyle(color: Colors.white, fontSize: 48.sp));
    } else if (duration >= 6 && duration <= 10) {
      return Text(LocaleKeys.sleep_ratio_normal.ts, style: TextStyle(color: Colors.white, fontSize: 48.sp));
    } else {
      return Text(LocaleKeys.sleep_ratio_height.ts, style: TextStyle(color: Colors.white, fontSize: 48.sp));
    }
  }
}
